package com.imooc.o2o.util;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

public class EncryptPropertyPlaceholderConfiguer extends PropertyPlaceholderConfigurer{
	// 需要加密的字段数组
	private String[] encryptPropNames = {"jdbc.username", "jdbc.password"};
	
	/**
	 * 对关键属性进行转换
	 */
	@Override
	protected String convertProperty(String propertyName, String propertyValue) {
		if(isEncryptProp(propertyName)) {
			return DESUtil.getDecryptString(propertyValue);
		} else {
			return propertyValue;
		}
	}

	private boolean isEncryptProp(String propertyName) {
		for(String str: encryptPropNames) {
			if(str.equals(propertyName)) {
				return true;
			}
		}
		return false;
	}
}
